package com.ahcfl.controller;

import com.ahcfl.dto.PageBean;
import com.ahcfl.dto.ResponseWrap;
import com.ahcfl.pojo.User;
import com.ahcfl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/findUserByPageAndName")
    public ResponseWrap findUserByPageAndName(int pageNum, int pageSize, String name){

        PageBean<User> pageBean = userService.findUserByPageAndName(pageNum,pageSize,name);
        ResponseWrap responseWrap = new ResponseWrap(pageBean);
        return responseWrap;
    }


    @RequestMapping("/saveUser")
    public ResponseWrap save(User user){
        boolean flag = userService.save(user);
        ResponseWrap responseWrap = new ResponseWrap(flag);
        return responseWrap;
    }


    @RequestMapping("/deleteUserById")
    public ResponseWrap save(int id){
        boolean flag = userService.deleteUserById(id);
        ResponseWrap responseWrap = new ResponseWrap(flag);
        return responseWrap;
    }


    @RequestMapping("/updateUser")
    public ResponseWrap updateUser(User user){
        boolean flag = userService.updateUser(user);
        ResponseWrap responseWrap = new ResponseWrap(flag);
        return responseWrap;
    }
}
